<html>
<?php
    require_once("menu.php");
	require_once('controllers/squadra.php');
	require_once("controllers/lega.php");
	$htmlLeghe = "";
	$cur_lega = null;
	$lega_id = -1;
	if(isset($_GET['l'])){
		$lega_id = $_GET['l'];
	}else{
		$lega_id = Lega::getIdPrimaLega();
	}
	
	$htmlLeghe = getMenuLeghe("?", $lega_id, $cur_lega);
?>
	<head>
		<title>Fantacalcio - Rose</title>
		<link rel="stylesheet" href="fantacalcio.css" type="text/css"/>
		<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
	</head>
	<body>
		<table class="pageTable" cellpadding='0' cellspacing='0'>
			<tr>
				<td>
					<?php echo printMasterMenu('Rose'); ?>
					
				</td>
				
			</tr>
			<tr>
				<td class='contentPage'>
					<table style="width:100%" class="">
						<tr>
							<td colspan="2" class="pageTitle">Rose&nbsp;<?php if($cur_lega != null) echo "della lega " . $cur_lega->getNome(); ?></td>
							
						</tr>
						<tr>
							<td style="vertical-align:top;width:150px;"><?php echo $htmlLeghe; ?></td>
							<td style="vertical-align:top;padding-left:20px;">
								<?php 

								$squadre = caricaSquadre($lega_id);								
								/*Adesso controlla se in query string è stato sepecificato quale
								 squadra caricare altrimenti carica la prima*/
								$teamId = 1;
								if(isset($_GET['team'])){
									$teamId = $_GET['team'];
								}
								$squadra = Squadra::caricaSquadra($teamId, $cur_lega->getStagione());

								//Crea il menu con i nomi delle squadre
								echo "<div style='display:inline;'>";
								//echo "<ul style='dispaly:inline'>";
								echo "<table style='width:100%; ". 
									//" border-style: solid; border-width: 1px; border-color: rgb(187,187,187); " .
									"background-color: rgb(136,136,136); '" . 
									" cellpadding='0' cellspacing='2' border='0'><tr>";

								for($i = 0; $i < count($squadre); $i++){
									//echo "<li class='menuSquadre'>";
									$otherClass = $teamId==$squadre[$i]->getId() ? "menuSquadreSel" : "";
									
									echo "<td class='menuSquadre $otherClass'>";
									echo "<a style='display:block;' class='menuSquadre $otherClass' href='rose.php?team=" . 
										$squadre[$i]->getId() . "&l=$lega_id'>";
									echo $squadre[$i]->getNome() . "</a>";
									//echo "</li>";
									echo "</td>";
								}
								//echo "</ul>";
								echo "</tr></table>";
								echo "</div>";
								$styleFirstRow = "style='width:65px;text-align:center;border-left: solid 1px rgb(23,128,128);'";
								echo "<br /><br />";
								echo "<div style='color:rgb(50,128,128);font-size:15px;'> " . $squadra->getNome() .
									" - " . $squadra->getAllenatore() . "</div>";
								echo "<br />";
								echo "<div style='color:blue;'>Budget rimanente " . $squadra->getBudget() ." &pound;</div><br />";
								//Adesso visualizza la rosa dei calciatori della squadra
								echo "<table style='' border='0' cellpadding='0' cellspacing='0'><tr>";
								echo "<td class='roseHeader' $styleFirstRow>Ruolo</td>";
								echo "<td class='roseHeader' style='width:170px'>Nome</td>";
								echo "<td class='roseHeader' style='width:105px'>Squadra</td>";
								echo "<td class='roseHeader' style='width:85px'>Stato</td>";
								echo "<td class='roseHeader' style='width:130px'>Costo FMLD</td>";
								echo "</tr>";
								for($i = 0; $i < $squadra->getNumGiocatori(); $i++){
									$g = $squadra->getGiocatore($i);
									$rowStyle = " class = 'roseRow' id = 'roseRow_" . ($i%2) . "'" ;
									echo "<tr>";
									echo "<td $rowStyle $styleFirstRow>" . $g->getRuolo() . "</td>";
									echo "<td $rowStyle>" . $g->getNome() ."</td>";
									echo "<td $rowStyle>" . $g->getSquadra() ."</td>";
									echo "<td $rowStyle>" . $g->getStato() ."</td>";
									echo "<td $rowStyle style='text-align:right'>" . $g->getCosto() . " &pound; </td>";
									echo "</tr>";
								}
								echo "</table><p>&nbsp;</p>";			
								?>
							</td>
						</tr>
					</table>
				</td>
				
			</tr>
			<tr>
				<td>
					<?php printFooter() ?>
				</td>
			</tr>
		</table>
	</body>
	
</html>
